package com.iteaj.iot;


/**
 * <p>协议工厂</p>
 * Create Date By 2020-09-18
 * @author iteaj
 * @since 1.7
 */
public abstract class ProtocolFactory<T extends SocketMessage> implements IotProtocolFactory<T> {

    /*报文管理器*/
    private ProtocolTimeoutStorage delegation;

    public ProtocolFactory() { }

    public ProtocolFactory(ProtocolTimeoutStorage delegation) {
        this.delegation = delegation;
    }

    @Override
    public AbstractProtocol get(String key) {
        return (AbstractProtocol) delegation.get(key);
    }

    @Override
    public AbstractProtocol add(String key, Protocol val) {
        return (AbstractProtocol) delegation.add(key, val);
    }

    @Override
    public AbstractProtocol add(String key, Protocol protocol, long timeout) {
        return (AbstractProtocol) delegation.add(key, protocol, timeout);
    }

    @Override
    public AbstractProtocol remove(String key) {
        if(key == null) return null;

        return (AbstractProtocol) delegation.remove(key);
    }

    @Override
    public boolean isExists(String key) {
        return delegation.isExists(key);
    }

    @Override
    public Object getStorage() {
        return delegation.getStorage();
    }

    public ProtocolTimeoutStorage getDelegation() {
        return delegation;
    }

    public void setDelegation(ProtocolTimeoutStorage delegation) {
        this.delegation = delegation;
    }
}
